package ar.com.maddes.creenciasadventistas;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SimpleCursorAdapter;
import ar.com.maddes.creenciasadventistas.database.Creencia;
import ar.com.maddes.creenciasadventistas.database.DatabaseHelper;
import ar.com.maddes.creenciasadventistas.ui.PagerAdapter;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;

public class StripActivity extends SherlockFragmentActivity implements
		ActionBar.OnNavigationListener {

	ViewPager mViewPager; 
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_strip);

		DatabaseHelper.instanciate(this);
		
		// Set up the action bar.
		final ActionBar actionBar = getSupportActionBar();
		// actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		actionBar.setDisplayShowTitleEnabled(false);
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

		// Set up the dropdown list navigation in the action bar.
		actionBar.setListNavigationCallbacks(
		// Specify a SpinnerAdapter to populate the dropdown list.
				new SimpleCursorAdapter(actionBar.getThemedContext(),
						android.R.layout.simple_list_item_1, DatabaseHelper.getTitles(),
						new String[] { Creencia.TITLE },
						new int[] { android.R.id.text1 })
				, this);


		PagerAdapter pagerAdapter = new PagerAdapter(
				getSupportFragmentManager());

		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(pagerAdapter);
		mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
			@Override
			public void onPageSelected(int position) {
				// TODO: uncomment after implementing actionBar
				actionBar.setSelectedNavigationItem(position);
			}
		});
	}

	@Override
	protected void onStop() {
		super.onStop();
		DatabaseHelper.closeDatabase();
	}

	@Override
	public boolean onNavigationItemSelected(int position, long id) {
		// TODO Auto-generated method stub
		mViewPager.setCurrentItem(position);
		return false;
	}
}
